<template>
  <view class="studentList commonDiv">
    <u-navbar
      leftText="返回"
      title="每一项的进度"
      :safeAreaInsetTop="true"
      @leftClick="backPre"
      >
        <view
          class="u-nav-slot"
          slot="right"
          @click="backTo"
        >
        <view class="icon iconfont icon-shouye" style="font-weight: 600;"></view>
      </view>
    </u-navbar>
    <view class="top">
      <view class="top-inner">
        <view class="nav-list margin-top">
          <navigator hover-class="none" :class="'nav-li bg-kuxuan' + (index + 1) + ' ' + ((activeTab == 'doing' && item.title == 'doing') ? 'doingActive' : (activeTab == 'done' && item.title == 'done') ? 'doneActive' : '')"
            v-for="(item, index) in kuxuan" :key="index" @click="changeTab(item)">
            <view class="nav-name">{{ item.name }}</view>
            <text :class="'icon iconfont icon-' + item.icon"></text>
          </navigator>
        </view>
      </view>
      <view class="totalBox"> 
        <text :class="'icon iconfont icon-' + (activeTab == 'doing' ? 'daichuli2' : 'yiwancheng')"></text>
        {{ activeTab == 'doing' ? '未完成' : '已完成' }}
        <text style="font-size: 20px;font-weight: 600;padding: 0 6px;"> {{totalBak}} / {{allBak}}</text> 
        </view>
      <view class="search-top">
        <view class="inner">
          <view class="inner-box">
            姓名：
            <u--input placeholder="请输入姓名" v-model="searchForm.name"></u--input>
          </view>
        </view>
        <view class="inner">
          <view class="inner-box">
            <u-button text="清空" style="width: 100px;margin: 0 10px;" @click="clearHandle"></u-button>
            <u-button type="primary" text="搜索" style="width: 100px;margin: 0 0 0 10px;"
              @click="searchHandle"></u-button>
          </view>
        </view>
      </view>
    </view>
    <view class="bot">
      <ua-table
        :columns="column"
        :data="data"
        :stripe="true"
        :border="true"
        :headerBold="true"
        headerBgColor="#f3f6f9"
        headerColor="#333"
        size='14px'
        height="calc(100vh - 230px)"
        style="border:1px solid #eee;"
      >
        <template #default="{row, col, index}">
          <block v-if="col.slot == 'btns'">
            <u-button style="width: 110px;" type="primary" v-if="activeTab == 'doing'" @click="buttonEdit(row, index)">
              <text class="icon iconfont icon-tijian"></text>去体检
            </u-button>
            <u-button style="width: 110px;" type="success" v-if="activeTab == 'done'" @click="buttonEdit(row, index)">
              <text class="icon iconfont icon-xuehua"></text>去查看
            </u-button>
          </block>
        </template>
      </ua-table>
      <view class="page-box">
        <page-pagination class="test-pagination" :numAround="true" :total="page.total"
          layout="page,prev,next,limit,total" :pageSizes="[20, 50, 100, 500]" :pageSize="page.limit"
          @sizeChange="sizeChange" color="#00796B" @pageChange="pageChange">
        </page-pagination>
      </view>
    </view>
  </view>
</template>
<script>
import mRequest from '@/api/index.js'
import hccmStore from '@/common/hccm-store.js'
export default {
  data () {
    return {
      totalBak: 0,
      allBak: 0,
      activeProject: '',
      activeTab: '',
      kuxuan: [
        {
          title: "doing",
          name: "未完成",
          icon: 'daichuli2',
          color: "xueshengtongji-01"
        },
        {
          title: "done",
          name: "已完成",
          icon: 'yiwancheng',
          color: ""
        },
      ],

      // end
      searchForm: {
        name: ''
      },
      page: {
        limit: 20,
        page: 1,
        total: 0
      },
      column:[
        { type:'index', align: 'center', fixed:true,width:70 },
        { prop: 'name', label: '姓名', align: 'center', fixed:true, width:120,},
        { prop: 'number', label: '学号', align: 'center', width: 140},
        { prop: 'sex', label: '性别', width:90, align: 'center'},
        { prop: 'year', label: '入学年份', width:110, align: 'center'},
        { prop: 'grade', label: '年级', width:110, align: 'center'},
        { prop: 'classs', label: '班级', width:110, align: 'center'},
        { prop: 'birthday', label: '年龄', width:90, align: 'center'},
        { prop: 'idCard', label: '身份证号', width:160,align: 'center'},
        // { prop: 'address', label: '家庭住址', width:200, align: 'center'},
        { prop: 'school', label: '学校', width: 200, align: 'center',},
        {slot: 'btns', label: '操作', align: 'center', width: 150, fixed: 'right'}, // 操作
      ],
      data: []
    }
  },
  methods: {
    backPre(){
      uni.navigateBack({
        delta: 1 // delta值为1时表示返回上一级页面
      })
    },
    backTo(){
      uni.reLaunch({
        url: '/pages/home/index'
      })
    },
    buttonEdit(val){
      uni.navigateTo({
        url:`/pages/home/inspectDetail/index?activeProject=${this.activeProject}&studentId=${val.id}`
      })
    },
    changeTab(val){
      if(this.activeTab !== val.title){
        this.activeTab = val.title
        this.getList()
        this.getTotalCount()
      }
    },
    handleLongPress (row, index, column) {
      console.log(row)
      console.log(index, column)
      console.log(row[column.name])
      uni.setClipboardData({
        data: row[column.name],
        success: () => {
          console.log('复制成功')
          // 可以添加用户提示复制成功
        },
        fail: () => {
          console.log('复制失败')
          // 可以添加用户提示复制失败
        }
      })
      return
      // 获取触发事件的DOM元素
      const target = event.target
      // 判断是否为td元素，并且内容不为空
      if (target.nodeName === 'TD' && target.textContent.trim() !== '') {
        // 使用uni.setClipboardData将内容设置到剪贴板
        uni.setClipboardData({
          data: target.textContent,
          success: () => {
            console.log('复制成功')
            // 可以添加用户提示复制成功
          },
          fail: () => {
            console.log('复制失败')
            // 可以添加用户提示复制失败
          }
        })
      }
    },
    sizeChange (val) {
      console.log(val)
      this.page.limit = val
      this.page.page = 1
      this.data = []
      this.getList()
    },
    pageChange(val){
      console.log(val)
      this.page.page = val
      this.data = []
      this.getList()
    },
    searchHandle () {
      this.page.page = 1
      this.data = []
      this.getList()
    },
    clearHandle () {
      this.page.page = 1
      this.searchForm = {}
      this.data = []
      this.getList()
    },
    getTotalCount(){
      mRequest.queryStudentList({
        limit: this.page.limit,
        page: this.page.page,
        projectStatus: this.activeTab == 'doing' ? 0 : 1, //(0:未完成 1:已结束)
        project: this.activeProject == 1 ? '第一项' : this.activeProject == 2 ? '第二项' : this.activeProject == 3 ? '第三项' : '',
        inspectId: hccmStore.getChooseInspectId()
      }).then(res => {
        this.totalBak = res.data.total
      })
    },
    getAll(){
      mRequest.queryStudentList({
        limit: this.page.limit,
        page: this.page.page,
        project: this.activeProject == 1 ? '第一项' : this.activeProject == 2 ? '第二项' : this.activeProject == 3 ? '第三项' : '',
        inspectId: hccmStore.getChooseInspectId()
      }).then(res => {
        this.allBak = res.data.total
      })
    },
    getList () {
      mRequest.queryStudentList({
        limit: this.page.limit,
        page: this.page.page,
        name: this.searchForm.name,
        projectStatus: this.activeTab == 'doing' ? 0 : 1, //(0:未完成 1:已结束)
        project: this.activeProject == 1 ? '第一项' : this.activeProject == 2 ? '第二项' : this.activeProject == 3 ? '第三项' : '',
        inspectId: hccmStore.getChooseInspectId()
      }).then(res => {
        this.data = res.data.records
        this.page.total = res.data.total
      })
    },
    pullUpLoadingAction () {
      if (this.page.total <= this.page.limit * this.page.page) {
        return
      } else {
        this.page.page++
        this.getList()
      }
    },
  },
  onLoad (options) {
    this.activeProject = options.activeProject
    if (this.activeProject) {
      uni.setNavigationBarTitle({
        title: this.activeProject == 1 ? '第一项检查进度' : this.activeProject == 2 ? '第二项检查进度' : this.activeProject == 3 ? '第三项检查进度' : '检查详情'
      })
    }
    this.activeTab = 'doing'
    this.getList()
    this.getTotalCount()
    this.getAll()
    console.log(hccmStore.getChooseInspectId())
  },
  watch:{
  }
}
</script>
<style lang='scss'>
.studentList {
  display: flex;
  height: calc(100vh - 1px);
  flex-direction: column;
  padding: 100px 20px 20px;
  box-sizing: border-box;

  .top {
    height: auto;
    width: 100%;

    .search-top {
      font-size: 14px;
      // overflow-x: auto;
      flex-wrap: wrap;
      display: flex;

      .inner {
        flex: 0 0 200px;
        /* 确保每个子元素有固定宽度 */
        display: inline-block;
        padding-right: 20px;
        padding-bottom: 10px;

        .inner-box {
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }

    .search-bot {
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }

  .bot {
    flex: 1;
    // height: calc(100vh - 100px);
    overflow: auto;
    display: flex;
    flex-direction: column;

    .page-box {
      height: 50px;
      width: 100%;
      display: flex;
      align-items: flex-end;
    }
  }

  .totalBox{
    font-size: 18px;
    padding: 20px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .iconfont{
      color: red;
      font-weight: 600;
      font-size: 20px;
      padding-right: 4px;
    }
    .icon-daichuli2{
      color: #BF360C;
    }
    .icon-yiwancheng{
      color: #1B5E20;
    }
  }
  .nav-list {
    display: flex;
    padding: 0px 20px 0px;
    justify-content: center;
  }

  .nav-li {
    padding: 20px 20px 20px 8px;
    border-radius: 6px;
    width: 45%;
    margin: 0 2.5% 8px;
    background-image: url('@/static/img/nav-bg.png');
    background-size: cover;
    background-position: center;
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .iconfont {
      font-size: 40px;
    }
  }

  .nav-li::after {
    content: "";
    position: absolute;
    z-index: -1;
    background-color: inherit;
    width: 100%;
    height: 100%;
    left: 0;
    bottom: -10%;
    border-radius: 10px;
    opacity: 0.2;
    transform: scale(0.9, 0.9);
  }

  .nav-li.cur {
    color: #fff;
    background: rgb(94, 185, 94);
    box-shadow: 4px 4px 6px rgba(94, 185, 94, 0.4);
  }

  .nav-name {
    font-size: 16px;
    text-transform: Capitalize;
    margin-top: 0;
    padding: 10px 0 14px 20px;
    position: relative;
  }

  .nav-name::before {
    content: "";
    position: absolute;
    display: block;
    width: 40px;
    height: 6px;
    background: #fff;
    bottom: 0;
    right: -20px;
    opacity: 0.5;
  }

  .nav-name::after {
    content: "";
    position: absolute;
    display: block;
    width: 100px;
    height: 1px;
    background: #fff;
    bottom: 0;
    right: 0;
    opacity: 0.3;
  }

  .nav-name::first-letter {
    font-weight: bold;
    font-size: 24px;
    margin-right: 1px;
  }

  .title-header {
    display: flex;
    font-size: 28px;
    padding-bottom: 40rpx;
    align-items: center;
    justify-content: center;
    text-align: center;
    /* padding: 40rpx 0 0 0; */
    font-weight: bold;
  }

  .title-text {
    background-image: -webkit-linear-gradient(60deg, #388E3C, #26A69A);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .title-text-des {
    font-size: 34px;
    font-weight: 600;
    background-image: -webkit-linear-gradient(60deg, $u-grey-darken, $u-blue-grey-darken);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .bg-kuxuan1 {
    background-color: #BF360C80;
    color: #fff;
  }
  .doingActive{
    background-color: #BF360C;
  }
  .bg-kuxuan2 {
    background-color: #1B5E2080;
    color: #fff;
  }
  .doneActive{
    background-color: #1B5E20;
  }

  .qr-box {
    height: 200px;
    width: 200px;
    background: #f5f5f5;
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;

    .iconfont {
      font-size: 60px;
      color: $u-primary;
    }
  }
  ::deep(.ua__thead-th){
    font-size: 16px !important;
    height: 40px;
    line-height: 40px;
  }
  ::deep(.ua__tbody-td){
    font-size: 14px !important;
    height: 34px;
    line-height: 34px;
  }
}
::deep(.ua__table-thead){
  .ua__thead-th{
    font-size: 12px !important;
  }
}
</style>